package com.zhs.smartmall.ware.service.impl;


import com.zhs.smartmall.ware.model.WmsPurchase;
import com.zhs.smartmall.ware.dao.WmsPurchaseDao;
import com.zhs.smartmall.ware.service.IWmsPurchaseService;
import com.zhs.smartmall.ware.dto.WmsPurchaseDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class WmsPurchaseServiceImpl extends ServiceImpl< WmsPurchaseDao, WmsPurchase> implements IWmsPurchaseService {

    @Resource
    private WmsPurchaseDao wmsPurchaseDao;

    @Override
    @Transactional
    public R addOrUpdate(WmsPurchaseDto wmsPurchaseDto) {
        if (BeanUtil.isEmpty(wmsPurchaseDto)) throw new ServiceException("数据不能为空");
        WmsPurchase wmsPurchase = new WmsPurchase();
        BeanUtil.copyProperties(wmsPurchaseDto,wmsPurchase);
        if (wmsPurchaseDto.getId() == null){
            wmsPurchaseDao.insert(wmsPurchase);
            return R.ok("数据插入成功");
        }else {
            wmsPurchaseDao.updateById(wmsPurchase);
            return R.ok("数据更新成功");
        }
    }
}